package model.dao;

import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;


public class LoginDao {
	int User_Id;
	String User_Name;
	String User_Pwd;
	String User_Sex;
	String User_Place;
	String User_Tel;
	String User_RealName;
	int User_Age;
	String User_Email;
	Connection cn=null;
	Statement st=null;
	PreparedStatement pt=null;
	ResultSet rs=null;
	public void init()
	{
			try {
				cn = DriverManager.getConnection("proxool.DbPool");
	            /*System.out.println("Success loading  MySQL Driver...");*/
	        } catch (Exception e) {
	            System.out.println("Error loading MySQL Driver...");
	            e.printStackTrace();
	        }
	}
	public void close()
	{
		try {
			if(rs!=null){rs.close();}
			if(pt!=null){pt.close();}
			if(st!=null){st.close();}
			if(cn!=null){cn.close();}
			
		} catch (Exception e) {
		}
		
	}
	public boolean search(String name,String pwd)
	{
		init();
		try {
			String url="select * from User_Info where User_Name='"+name+"'and User_Pwd='"+pwd+"'";
			st=cn.createStatement();
			rs=st.executeQuery(url);
			if(rs.next())
			{
			   /* User_Id=rs.getInt(1);
			    User_Name=rs.getString(2);*/
				User_Id=rs.getInt(1);
				User_Name=rs.getString(2);
				User_Pwd=rs.getString(3);
				User_Sex=rs.getString(4);
				User_Place=rs.getString(5);
				User_Tel=rs.getString(7);
				User_RealName=rs.getString(9);
				User_Age=rs.getInt(10);
				User_Email=rs.getString(11);
				return true;
			}
			else return false;

		} catch (Exception e) {
			System.out.print("search error!");
			e.printStackTrace();
			return false;
		}finally {
			close();
			}
		
		
	}
	public String getUser_Pwd() {
		return User_Pwd;
	}
	public String getUser_Sex() {
		return User_Sex;
	}
	public String getUser_Place() {
		return User_Place;
	}
	public String getUser_Tel() {
		return User_Tel;
	}
	public String getUser_RealName() {
		return User_RealName;
	}
	public int getUser_Age() {
		return User_Age;
	}
	public String getUser_Email() {
		return User_Email;
	}
	public int getUser_Id() {
		return User_Id;
	}
	public String getUser_Name() {
		return User_Name;
	}
 

}
